home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir42 / c7105.zip / FILE.TPX < prev    next >
Text File  |  1994-03-02  |  22KB  |  373 lines

  1. #!┌───────────────────────────┤Template Segment├───────────┬─────────────────┐
  2. #!│                                FILE.TPX                │Version: 3007.105│
  3. #!├───────────────────────────────┤Contents├───────────────┴─────────────────┤
  4. #!│Structure             Type       Description                              │
  5. #!│────────────────────  ─────────  ─────────────────────────────────────────│
  6. #!│File                  PROCEDURE  Select a file from a directory listing   │
  7. #!│SetFileSymbols        GROUP      Sets Code Generation Symbols             │
  8. #!│SetFileErrors         GROUP      Generates ?Cancel Button Missing Warning │
  9. #!├───────────────────────────────┤Comments├─────────────────────────────────┤
  10. #!│Version   Comments                                                        │
  11. #!│────────  ────────────────────────────────────────────────────────────────│
  12. #!│3007.000  Release of CDD3 version 3007 templates                          │
  13. #!│3007.100  Repaired File Template                                          │
  14. #!│3007.103  Repaired File Template                                          │
  15. #!│3007.104  Repaired File Template                                          │
  16. #!│3007.105  Repaired File Template                                          │
  17. #!└──────────────────────────────────────────────────────────────────────────┘
  18. #!
  19. #PROCEDURE(File,'Select a file from a directory listing'),SCREEN
  20. #!
  21. #!┌──────────────────────────┤Procedure Template├──────────┬─────────────────┐
  22. #!│                                  File                  │Version: 3007.105│
  23. #!├──────────────────────────────┤Description├─────────────┴─────────────────┤
  24. #!│ The File template creates a procedure to allow a user to select a file.  │
  25. #!│ The file name with its full path will be saved in the variable entered   │
  26. #!│ at the 'Filename Variable' prompt.  If this field is left blank the      │
  27. #!│ default of GLO:Filespec is used.  (GLO:Filespec has been entered in      │
  28. #!│ Clarion's Default Application file for your convenience.  It will be     │
  29. #!│ Smart-linked out of your final .EXE if not used.)                        │
  30. #!│                                                                          │
  31. #!│ If a Next Procedure is requested (ie: a procedure created with the View  │
  32. #!│ template) it will be called just prior to returning to the calling       │
  33. #!│ procedure.                                                               │
  34. #!├───────────────────────────────┤Comments├─────────────────────────────────┤
  35. #!│Version   Comments                                                        │
  36. #!│────────  ────────────────────────────────────────────────────────────────│
  37. #!│3007.000  Release of CDD3 version 3007 templates                          │
  38. #!│3007.100  In FillQueues ROUTINE, the call to SELECT(?FileList,1) was      │
  39. #!│          being made even if ?FileList was not defined.                   │
  40. #!│3007.103  In ProcedureReturn ROUTINE, the call to SETPATH needed to have  │
  41. #!│          the trailing "\" stripped off of the directory path.            │
  42. #!│3007.104  In ProcedureReturn ROUTINE, the call to SETPATH was missing a   │
  43. #!│          trailing parentheses to close the setpath statement.            │
  44. #!│3007.105  In ProcedureReturn ROUTINE, the call to SETPATH was removing the│
  45. #!│          trailing backslash on a set to the root directory.              │
  46. #!│          Repaired typographical error in comments (begining)             │
  47. #!│          Replaced RETURNs in FillQueues ROUTINE with DO ProcedureReturn  │
  48. #!└──────────────────────────────────────────────────────────────────────────┘
  49. #!
  50. #PROTOTYPE('')                                   #! No special prototype
  51. #INSERT(%StandardHeader)                         #! Procedure Comment Block
  52. #MAP('GETDIR.INC')                               #! Include Procs in MAP
  53. #DISPLAY(' ')                                    #! Blank Line on Props Scrn
  54. #PROMPT('Filename &Variable',FIELD),%SaveFilenameVar
  55. #PROMPT('Initial Directory',@S30),%StartDir
  56. #PROMPT('Beginning File Mask',@S12),%StartMask
  57. #PROMPT('Next Procedure',PROCEDURE),%NextProcedure
  58. #PROMPT('Reselect Upon Return',CHECK),%AllowReselect
  59. #PROMPT('Blank Name On Cancel',CHECK),%ClearOnCancel
  60. #PROMPT('Allow Drive Searches',CHECK),%AllowDriveSearch
  61. #INSERT(%SetFileSymbols)                         #! Set Generation Flags
  62. #INSERT(%SetFileErrors)                          #! Warn Developer, if needed
  63. %Procedure       PROCEDURE                       #<!%ProcedureDescription
  64. %LocalData                                       #! Declare Local Data
  65. %ScreenStructure                                 #! Declare Screen Structure
  66. DirString   CSTRING(64)                          #<! Used for Directory to search
  67. SaveDir     LIKE(DirString)                      #<! Used to hold beginning path
  68. SaveSelect  LONG                                 #<! Used to hold selected field
  69. DirInfo     GROUP                                #<! Necessary DOS file group
  70.               BYTE,DIM(21)                       #<! Used by findfirst
  71. Attrib        BYTE                               #<! Attribute in DOS format
  72. DosTime       SHORT                              #<! Time in DOS format
  73. DosDate       SHORT                              #<! Date in DOS format
  74. Filesize      LONG                               #<! Size in BYTES
  75. FileName      CSTRING(13)                        #<! File name
  76.             END                                  #<! End GROUP
  77. #IF(%AllowDriveSearch)                           #! IF allowing to search drives
  78. DriveNumber USHORT                               #<! Used for Drive search
  79. CheckReady  STRING(3)                            #<! Used to check if Drive is ready
  80. #ENDIF                                           #! END (IF allowing...)
  81. #EMBED('Data Section')                           #! Embedded Source Code
  82.   CODE                                           #<! Begin Processing Code
  83.   #EMBED('Setup Procedure')                      #! Embedded Source Code
  84.   OPEN(%Screen)                                  #<! Open the screen
  85.   #EMBED('Setup Screen')                         #! Embedded Source Code
  86.   #IF(%StartMask)                                #! IF Initial File Mask
  87.   FileMask = '%StartMask'                        #<!Set the begining file mask
  88.   #ELSE
  89.   FileMask = '*.*'                               !Set the beginning file mask
  90.   #ENDIF
  91.   SaveDir = PATH()                               !Save the Starting Directory
  92.   IF SUB(SaveDir,LEN(CLIP(SaveDir)),1) <> '\'    ! Last character not backslash?
  93.     SaveDir = CLIP(SaveDir) & '\'                ! Add the trailing '\'
  94.   END
  95.   #IF(%StartDir)
  96.   Directory = UPPER(%StartDir)                   #<!Change to the requested
  97.   SETPATH(Directory)                             ! Starting directory
  98.   Directory = PATH()                             ! Reread the current path
  99.   IF SUB(Directory,LEN(CLIP(Directory)),1) <> '\' ! Last character not backslash?
  100.     Directory = CLIP(Directory) & '\'            ! Add the trailing '\' for display
  101.   END
  102.   #ELSE
  103.   Directory = SaveDir                            !Set to the Current Directory
  104.   #ENDIF
  105.   DO FillQueues                                  !Fill the screen queues
  106.   LOOP                                           !Main ACCEPT loop
  107.     #INSERT(%GenerateFormulas)
  108.     #EMBED('Top of Accept Loop')                 #! Embedded Source Code
  109.     CASE SELECTED()                              #<! Jump to field setup routine
  110.     #INSERT(%ScreenSetupRoutines)
  111.     END                                          #<! End CASE
  112.     ACCEPT                                       ! ACCEPT keyboard input
  113.     #INSERT(%HotKeyRoutines)
  114.     CASE FIELD()                                 ! Jump to field edit routine
  115.   #FOR(%ScreenField)
  116.     #IF(%ScreenField = '?FileMask')
  117.     OF ?FileMask                                 ! Completed file mask field
  118.     #IF(%ScreenFieldEdit)
  119.       %ScreenFieldEdit                           #<! File mask edit routine
  120.     #ENDIF
  121.       IF REFER()                                 !  If something was entered
  122.         Do FillQueues                            !   Fill queues with new mask
  123.       END                                        !  End IF
  124.     #ELSIF(%ScreenField = '?FileList')
  125.     OF ?FileList                                 ! FileList field edit
  126.       GET(FileQueue,CHOICE())                    !  Get selected file entry
  127.   #IF(%ScreenFieldEdit)
  128.       %ScreenFieldEdit                           #<! File list edit routine
  129.   #ENDIF
  130.       IF KEYCODE() = MouseLeft2 OR |             !  On mouse double click
  131.          KEYCODE() = EnterKey                    !    Or the Enter Key
  132.         SELECT(?OK)                              !   Select the OK button and
  133.         PRESS(EnterKey)                          !   Press Enter to complete
  134.       END                                        !  End IF
  135.     #ELSIF(%ScreenField = '?DirList')
  136.     OF ?DirList                                  ! Directory list field edit
  137.     #IF(%ScreenFieldEdit)
  138.       %ScreenFieldEdit                           #<! Directory edit routine
  139.     #ENDIF
  140.       IF SELECTED() = ?DirList                   !  If staying on this field
  141.         IF KEYCODE() = MouseLeft2 OR |           !   On mouse double click
  142.            KEYCODE() = EnterKey                  !     or the Enter Key
  143.           GET(DirQueue,CHOICE())                 !    Get the selected entry
  144.     #IF(%AllowDriveSearch)
  145.           IF LEN(CLIP(DirLine)) = 5 AND |        !  Are we looking at a drive?
  146.             SUB(DirLine,1,2) = '[-' AND |
  147.             SUB(DirLine,4,2) = '-]' AND |
  148.             SUB(DirLine,3,1) >= 'A' AND |
  149.             SUB(DirLine,3,1) <= 'Z'
  150.             CheckReady = SUB(DirLine,3,1) & ':'  ! Specify drive letter designation
  151.             IF STATUS(CheckReady) = 0            ! If drive not ready
  152.               CYCLE                              !   Don't change to it
  153.             END
  154.             Directory = CLIP(CheckReady)         ! Assign drive letter as new directory
  155.           ELSE
  156.             Directory = CLIP(Directory) & DirLine ! Create a new directory string
  157.           END
  158.     #ELSE
  159.           Directory = CLIP(Directory) & DirLine  ! Create a new directory string
  160.     #ENDIF
  161.           IF SUB(Directory,LEN(CLIP(Directory)),1) = '\' ! Last character a backslash?
  162.             Directory = SUB(Directory,1,LEN(CLIP(Directory))-1) ! Get rid of it before SETPATH
  163.           END
  164.           SETPATH(Directory)                     ! Set to current directory
  165.           Directory = PATH()                     ! Reread the current directory
  166.           IF SUB(Directory,LEN(CLIP(Directory)),1) <> '\' ! Last character not backslash?
  167.             Directory = CLIP(Directory) & '\'    ! Add the trailing '\' for display
  168.           END
  169.           Do FillQueues                          !    Fill the screen queues
  170.         END                                      !   End IF
  171.       END                                        !  End IF
  172.     #ELSIF(UPPER(%ScreenField) = '?OK')
  173.     OF ?Ok                                       ! Ok button field Edit
  174.   #IF(%ScreenFieldEdit)
  175.       %ScreenFieldEdit                           #<! OK button edit routine
  176.   #ENDIF
  177.       IF FileLine = '  NO MATCH     '            !  If no FileName selected
  178.   #IF(%DirQueueExists)
  179.         SELECT(?DirList)                         !   Select directory list
  180.   #ELSE
  181.         SELECT(?Cancel)                          !   Select cancel button
  182.   #ENDIF
  183.         CYCLE                                    !   Cycle to ACCEPT.
  184.       END                                        !  End IF
  185.       %SaveFilenameVar = CLIP(Directory) & FileLine #<! Save the Filename
  186.   #IF(%NextProcedure)
  187.       SETPATH(SaveDir)                           !  Return to starting path
  188.     #IF(%DirQueueExists)
  189.       FREE(DirQueue)                             !  Free the DirQueue memory
  190.     #ENDIF
  191.       FREE(FileQueue)                            !  Free the FileQueue memory
  192.       %NextProcedure                             #<! Call the Next procedure
  193.     #IF(%AllowReselect)
  194.       DO FillQueues                              !  Fill the screen queues
  195.       SELECT(?FileList)                          !  Select the file list
  196.       CYCLE                                      !  Return to ACCEPT input
  197.     #ELSE
  198.       DO ProcedureReturn                         #<! And leave the Procedure
  199.     #ENDIF
  200.   #ELSE
  201.       DO ProcedureReturn                         #<! And leave the Procedure
  202.   #ENDIF
  203.     #ELSIF(%ScreenField = '?Cancel')
  204.     OF ?Cancel                                   ! Cancel button field Edit
  205.   #IF(%ScreenFieldEdit)
  206.       %ScreenFieldEdit                           #<! Cancel button edit routine
  207.   #ENDIF
  208.       SETPATH(SaveDir)                           !  Return to starting path
  209.   #IF(%DirQueueExists)
  210.       FREE(DirQueue)                             !  Free the DirQueue memory
  211.   #ENDIF
  212.       FREE(FileQueue)                            !  Free the FileQueue memory
  213.   #IF(%ClearOnCancel)
  214.       CLEAR(%SaveFilenameVar)                    #<! Clear the filename variable
  215.   #ENDIF
  216.       DO ProcedureReturn                         #<! And leave the Procedure
  217.     #ELSIF(%ScreenFieldEdit)                     #!
  218.     OF %ScreenField                              #<! Completed %ScreenField
  219.       %ScreenFieldEdit                           #<! %ScreenField edit routine
  220.     #ENDIF                                       #!
  221.   #ENDFOR                                        #!
  222.     #INSERT(%PulldownEditRoutines)               #!
  223.     END                                          #<! End CASE FIELD()
  224.   END                                            #<! End LOOP
  225.   DO ProcedureReturn                             #<! And leave the Procedure
  226. !─────────────────────────────────────────────────────────────────────────────
  227. ProcedureReturn ROUTINE                          #<! return from the PROC
  228.   IF LEN(CLIP(SaveDir)) > 3                      ! If not on a root dir
  229.     SETPATH(SUB(SaveDir,1,LEN(CLIP(SaveDir))-1)) ! Return to starting path
  230.   END                                            ! END (IF not on a root dir)
  231.   #IF(%DirQueueExists)
  232.   FREE(DirQueue)                                 !Free the DirQueue memory
  233.   #ENDIF
  234.   FREE(FileQueue)                                !Free the FileQueue memory
  235.   DO EndOfProcedureEmbed                         #<! Process the final EMBED
  236.   RETURN                                         #<! END exit the PROC
  237. !─────────────────────────────────────────────────────────────────────────────
  238. EndOfProcedureEmbed ROUTINE                      #<! Process the final EMBED
  239. #EMBED('End of Procedure')                       #! Embedded Source Code
  240. !─────────────────────────────────────────────────────────────────────────────
  241. #EMBED('Custom Routines')                        #! Embedded Source Code
  242. !─────────────────────────────────────────────────────────────────────────────
  243. FillQueues ROUTINE
  244.   SaveSelect = SELECTED()                        !Save the current selected field
  245.   FREE(FileQueue)                                !Free the FileQueue
  246. #IF(%FileListExists)
  247.   SELECT(?FileList,1)                            !Reset file list box
  248. #ENDIF
  249. #IF(%DirQueueExists)
  250.   FREE(DirQueue)                                 !Free the DirQueue
  251.   SELECT(?DirList,1)                             !Reset Dir List box
  252.   DirString = CLIP(Directory) & '*.*'            !Set the subdirectory mask
  253.   IF NOT LEN(CLIP(DirString)) = 6                !If not in the root directory
  254.     DirLine = '..\'                              ! Make prior directory entry
  255.     ADD(DirQueue)                                ! Add to the DirQueue
  256.   END                                            !End IF
  257.   IF FindFirst(DirString,DirInfo,FA_DIREC) <> 0  !If unexpected error
  258.     DO ProcedureReturn                           !
  259.   END                                            !End IF
  260.   LOOP                                           !While entries found
  261.     IF FileName = '.' OR FileName = '..'         ! If the dot entries
  262.       IF FindNext(DirInfo) <> 0                  !  Get the next entry
  263.         BREAK                                    !   Break if unexpected error
  264.       END                                        !  End IF
  265.       CYCLE                                      !  Return to dot entry check
  266.     END                                          ! End IF
  267.     IF BAND(ATTRIB,10H)                          ! If a subdirectory is found
  268.       DirLine = FileName                         !  Fill the queue field
  269.       ADD(DirQueue)                              !  Add to the DirQueue
  270.       IF ERRORCODE() THEN BREAK.                 !  Break if unexpected error
  271.     END                                          ! End IF
  272.     IF FindNext(DirInfo) <> 0                    ! Get the next entry
  273.       BREAK                                      !  Break if unexpected error
  274.     END                                          ! End IF
  275.   END                                            !End LOOP
  276.   SORT(DirQueue,+DirLine)                        !Sort the directory listing
  277.   #IF(%AllowDriveSearch)
  278.   LOOP DriveNumber = 1 TO 26                     !Loop through drive numbers
  279.     IF IsAValidDrive(DriveNumber)                !Validate drive number
  280.        DirLine = '[-' & CLIP(CHR(DriveNumber-1+VAL('A'))) & '-]' !Format drive letter
  281.        ADD(DirQueue)                             ! Add to the DirQueue
  282.     END
  283.   END
  284.   #ENDIF
  285. #ENDIF
  286.   FileLine = 'Searching...'                      !Search message
  287.   ADD(FileQueue)                                 !Add to the FileQueue
  288.   DISPLAY                                        !Display new directory and message
  289.   FREE(FileQueue)                                !Free the FileQueue
  290.   DirString=CLIP(Directory) & FileMask           !Set the file mask
  291.   IF FindFirst(DirString,DirInfo,FA_NORMAL) <> 0 !If no matching files found
  292.     FileLine = '  NO MATCH  '                    ! Fill queue with message
  293.     ADD(FileQueue)                               ! Add to the FileQueue
  294.   Else                                           !Else matching file found
  295.     LOOP                                         ! While entries are found
  296.       IF BAND(ATTRIB,10H) = 0                    !  If entry is a file
  297.         FileLine = FileName                      !   Fill the queue field and
  298.         ADD(FileQueue)                           !   Add to the FileQueue
  299.         IF ERRORCODE() THEN BREAK.               !   Break if unexpected error
  300.       END                                        !  End IF
  301.       IF FindNext(DirInfo) <> 0                  !  Get the next entry
  302.         BREAK                                    !   Break if unexpected error
  303.       END                                        !  End IF
  304.     END                                          ! End LOOP
  305.   END                                            !End IF
  306.   SORT(FileQueue,+FileLine)                      !Sort the file listing
  307.   DISPLAY                                        !Display the new lists
  308.   SELECT(SaveSelect)                             !Reselect the previous selected field
  309. #!***************************************************************************
  310. #GROUP(%SetFileSymbols)
  311. #!
  312. #!┌────────────────────────────┤Template Group├────────────┬─────────────────┐
  313. #!│                            %SetFileSymbols             │Version: 3007.000│
  314. #!├──────────────────────────────┤Description├─────────────┴─────────────────┤
  315. #!│Purpose:      To setup symbols for generation of a procedure with the     │
  316. #!│              File template.                                              │
  317. #!│Called From:  PROCEDURE: File                                             │
  318. #!│Assumptions:  None                                                        │
  319. #!│Inserts:      None                                                        │
  320. #!│Symbols Set:  None                                                        │
  321. #!│Notes:        None                                                        │
  322. #!└──────────────────────────────────────────────────────────────────────────┘
  323. #!
  324. #IF(%SaveFilenameVar = %Null)
  325.   #SET(%SaveFilenameVar, 'GLO:FileSpec')
  326. #ENDIF
  327.   #SET(%DirQueueExists,%Null)
  328.   #SET(%FileMaskExists,%Null)
  329.   #SET(%FileListExists,%Null)
  330.   #SET(%DirectoryExists,%Null)
  331.   #SET(%FileOkExists,%Null)
  332.   #SET(%FileCancelExists,%Null)
  333.   #FOR(%ScreenField)
  334.     #IF(UPPER(%ScreenField) = '?DIRLIST')
  335.       #SET(%DirQueueExists,'YES')
  336.     #ELSIF(UPPER(%ScreenField) = '?FILEMASK')
  337.       #SET(%FileMaskExists,'YES')
  338.     #ELSIF(UPPER(%ScreenField) = '?FILELIST')
  339.       #SET(%FileListExists,'YES')
  340.     #ELSIF(UPPER(%ScreenField) = '?DIRECTORY')
  341.       #SET(%DirectoryExists,'YES')
  342.     #ELSIF(UPPER(%ScreenField) = '?OK')
  343.       #SET(%FileOkExists,'YES')
  344.     #ELSIF(UPPER(%ScreenField) = '?CANCEL')
  345.       #SET(%FileCancelExists,'YES')
  346.     #ENDIF
  347.   #ENDFOR
  348. #!***************************************************************************
  349. #GROUP(%SetFileErrors)
  350. #!
  351. #!┌────────────────────────────┤Template Group├────────────┬─────────────────┐
  352. #!│                             %SetFileErrors             │Version: 3007.000│
  353. #!├──────────────────────────────┤Description├─────────────┴─────────────────┤
  354. #!│Purpose:      To warn the developer of any template errors                │
  355. #!│Called From:  PROCEDURE: File                                             │
  356. #!│Assumptions:  None                                                        │
  357. #!│Inserts:      None                                                        │
  358. #!│Symbols Set:  None                                                        │
  359. #!│Notes:        None                                                        │
  360. #!└──────────────────────────────────────────────────────────────────────────┘
  361. #!
  362. #IF(%FileCancelExists <> 'YES')
  363.   #SET(%ErrorMessage,(%Procedure & ' WARNING:'))
  364.   #ERROR(%ErrorMessage)
  365.   #SET(%ErrorMessage,'   ?Cancel button is not found in the screen structure,')
  366.   #ERROR(%ErrorMessage)
  367.   #SET(%ErrorMessage,'   Exit code may not have been generated.')
  368.   #ERROR(%ErrorMessage)
  369.   #SET(%ErrorMessage,%Null)
  370.   #ERROR(%ErrorMessage)
  371. #ENDIF
  372. #CHAIN('Screen.tpx')
  373.